<?php

namespace app\api\controller;

use app\api\model\OauthOrderClass AS OrderClassModel;
use app\api\validate\Page;
use app\api\model\LangClassRecite;

class OauthOrderClass extends Base
{
    /**
     * 我购买的课程 -- 二级联动 -- 背单词 背句子等选择
     * @return array
     * @throws \think\Exception\DbException
     */
    public function select()
    {
        // 背诵类型，1单词，2句子
        $reciteType = input('type') ? input('type') : LangClassRecite::TYPE_WORD;
        $model = OrderClassModel::selectClasses($this->oauthInfo['id'], $reciteType);
        return self::sendResult(self::$okCode, $model);
    }

    /**
     * 我的课程
     * @return array
     * @throws \think\Exception\DbException
     */
    public function index()
    {
        $page = $data['page'] = input('page') ? input('page') : 1;
        $size = $data['size'] = input('size') ? input('size') : $this->pageSize;

        // 检测变量
        $validate = new Page();
        if (!$validate->check($data)) {
            return self::sendResult(102, [], $validate->getError());
        }

        $model = OrderClassModel::myClasses($this->oauthInfo['id'], $page, $size);
        return self::sendResult(self::$okCode, $model);
    }
}